//
//  MTControllerNotiViewController.m
//  ShiShiBang
//
//  Created by 宋宝强 on 16/9/23.
//  Copyright © 2016年 motianjituan. All rights reserved.
//



// 关闭    iOS 8 以上可用此方法
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]
#import "MTControllerNotiViewController.h"
#import "MTSwitchItem.h"
#import "MTTextItem.h"
#import "MTSettingGroupItem.h"
#import "MTArrowItem.h"

#import "MTMaskView.h"
#import "MTPickerTimeView.h"



@interface MTControllerNotiViewController ()<MTPickerTimeViewDelegate>
@property (nonatomic, strong) NSString  *time;
@end

@implementation MTControllerNotiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpGroup0];
    [self setUpGroup1];
    [self initNavigation];
    
}

-(void)initNavigation {
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"back"] highImage:[UIImage imageNamed:@"back anxia"] target:self action:@selector(backClick)];
    self.navigationItem.title = @"控制中心";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(0x45c75a)]  forBarMetrics:UIBarMetricsDefault];
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont boldSystemFontOfSize:17];
    attr[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:attr];
}

-(void)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)setUpGroup0 {
    
    MTSwitchItem *item0 = [MTSwitchItem itemWithImage:nil title:@"勿扰时段"];
//     MTSwitchItem *item1 = [MTSwitchItem itemWithImage:nil title:@"22:00-8:00"];
//    MTTextItem *item1 = [MTTextItem itemWithItem:nil title:@"22:00-08:00" subtitle:@"设置"] ;
     MTTextItem  *item1 = [MTTextItem itemWithImage:nil title:@"22:00-08:00"];
    NSArray *array =  @[item0, item1];
    MTSettingGroupItem *groupItem = [MTSettingGroupItem settingGroupItemWithRowArray:array headerT:nil footerT:@"开启勿扰时段时，这个阶段收不到订单通知"];

    [self.groupArray addObject:groupItem];
}

-(void)setUpGroup3 {
    
    MTSwitchItem *item0 = [MTSwitchItem itemWithImage:nil title:@"勿扰时段"];
    MTSwitchItem *item1 = [MTSwitchItem itemWithImage:nil title:self.time];
    NSArray *array =  @[item0, item1];
    MTSettingGroupItem *groupItem = [MTSettingGroupItem settingGroupItemWithRowArray:array headerT:nil footerT:@"开启勿扰时段时，这个阶段收不到订单通知"];
    
    [self.groupArray addObject:groupItem];
}
-(void)setUpGroup1 {
    
      MTSwitchItem *item0 = [MTSwitchItem itemWithItem:nil title:@"声音通知" subtitle:@"开启后新消息推送为声音提示"];
      MTSwitchItem *item1 = [MTSwitchItem itemWithImage:nil title:@"隐身接单"];
      NSArray *array =  @[item0,item1];
     MTSettingGroupItem *groupItem = [MTSettingGroupItem settingGroupItemWithRowArray:array headerT:nil footerT:@"开启后你不在出现在附近页面，但你依然可以收到来自系统的通知"];
    [self.groupArray addObject:groupItem];
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0];
    if (indexPath == index) {
        [MTMaskView show];
        
        MTPickerTimeView *pickView = [MTPickerTimeView pickerView];
        pickView.delegate = self;
    }
}

#pragma mark ------MTPickerTimeViewDelegate

- (void)pickerTimeView:(MTPickerTimeView *)timeView start:(NSString *)start end:(NSString *)end button:(UIButton *)btn {
    
    NSString *string = [NSString stringWithFormat:@"%@-%@",start,end];
    _time = string;
    
    [self.groupArray removeAllObjects];
    [self setUpGroup3];
    [self setUpGroup1];
    [self.tableView reloadData];
    
    [btn addTarget:self action:@selector(cancelBtn) forControlEvents:UIControlEventTouchUpInside];
}

-(void)cancelBtn {
    [self.groupArray removeAllObjects];
    MTSwitchItem *item0 = [MTSwitchItem itemWithImage:nil title:@"勿扰时段"];
    MTSwitchItem *item1 = [MTSwitchItem itemWithImage:nil title:@"22:00-8:00"];
    NSArray *array =  @[item0, item1];
    
    MTSettingGroupItem *groupItem = [MTSettingGroupItem settingGroupItemWithRowArray:array headerT:nil footerT:@"开启勿扰时段时，这个阶段收不到订单通知"];
    [self.groupArray addObject:groupItem];
    [self setUpGroup1];
    [self.tableView reloadData];
}

@end
